package com.rui.singleton.model;

/**
 * ThreadLocal单例
 * <p>
 * 不保证整个应用全局唯一，但保证线程内部全局唯一，以空间换时间，且线程安全。
 */
public class ThreadLocalSingleton {

    private static final ThreadLocal<ThreadLocalSingleton> threadLocalInstance = ThreadLocal.withInitial(() -> new ThreadLocalSingleton());

    private ThreadLocalSingleton() {
    }

    public static ThreadLocalSingleton getInstance() {
        return threadLocalInstance.get();
    }
}